package com.taptech.doufu.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.taptech.doufu.R;

import java.util.ArrayList;

@SuppressLint("HandlerLeak")
public class TagAapater extends BaseListAdapter
{

    ArrayList<String> dataList ;
    private LayoutInflater inflater; // 视图容器
    private boolean isFromTagNeed = false;


    public TagAapater(Context context, ArrayList<String> dataList)
    {
        this.dataList = dataList;
        inflater = LayoutInflater.from(context);
    }
    public TagAapater(Context context, ArrayList<String> dataList, boolean isFromTagNeed)
    {
        this.dataList = dataList;
        this.isFromTagNeed = isFromTagNeed;
        inflater = LayoutInflater.from(context);

    }
    public void setData(ArrayList<String> dataList)
    {
        this.dataList = dataList;
    }

    @Override
    public int getCount()
    {
        if (dataList != null){
            return dataList.size();
        }
        return 0;
    }

    public Object getItem(int arg0)
    {

        return dataList.get(arg0);
    }

    public long getItemId(int arg0)
    {

        return 0;
    }

    /**
     * ListView Item设置
     */
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder ;
        if (convertView == null)
        {
            convertView = inflater.inflate(R.layout.item_tag, parent, false);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.item_tag_title);
            holder.add_tv = (TextView) convertView.findViewById(R.id.item_tag_tv);
            holder.line_base = (View) convertView.findViewById(R.id.line_base);

            convertView.setTag(holder);
        } else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(dataList.get(position));
        if (isFromTagNeed)
        {
            holder.title.setGravity(Gravity.CENTER);
        }
        if (dataList.get(position).contains("%%") && position == 0)
        {
            holder.title.setText(dataList.get(position).replace("%%", ""));
            holder.title.setTextColor(Color.parseColor("#868686"));
            holder.title.setTextSize(20);
            holder.line_base.setVisibility(View.GONE);
            holder.add_tv.setVisibility(View.VISIBLE);
        } else
        {
            holder.add_tv.setVisibility(View.GONE);
            holder.line_base.setVisibility(View.VISIBLE);
            holder.title.setTextColor(Color.parseColor("#5d5d5d"));
            holder.title.setTextSize(15);
        }
        return convertView;
    }

    public class ViewHolder
    {
        public TextView title;
        public TextView add_tv;
        public View line_base;
    }

    @Override
    public void notifyDataSetChanged()
    {
        super.notifyDataSetChanged();

    }
}